package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.RyStockOverview;
import com.ruoyi.pims.service.IRyStockOverviewService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存概览Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/pims/overview")
public class RyStockOverviewController extends BaseController
{
    private String prefix = "pims/overview";

    @Autowired
    private IRyStockOverviewService ryStockOverviewService;

    @RequiresPermissions("pims:overview:view")
    @GetMapping()
    public String overview()
    {
        return prefix + "/overview";
    }

    /**
     * 查询库存概览列表
     */
    @RequiresPermissions("pims:overview:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RyStockOverview ryStockOverview)
    {
        startPage();
        List<RyStockOverview> list = ryStockOverviewService.selectRyStockOverviewList(ryStockOverview);
        return getDataTable(list);
    }

    /**
     * 导出库存概览列表
     */
    @RequiresPermissions("pims:overview:export")
    @Log(title = "库存概览", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RyStockOverview ryStockOverview)
    {
        List<RyStockOverview> list = ryStockOverviewService.selectRyStockOverviewList(ryStockOverview);
        ExcelUtil<RyStockOverview> util = new ExcelUtil<RyStockOverview>(RyStockOverview.class);
        return util.exportExcel(list, "库存概览数据");
    }

    /**
     * 新增库存概览
     */
    @RequiresPermissions("pims:overview:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存概览
     */
    @RequiresPermissions("pims:overview:add")
    @Log(title = "库存概览", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RyStockOverview ryStockOverview)
    {
        return toAjax(ryStockOverviewService.insertRyStockOverview(ryStockOverview));
    }

    /**
     * 修改库存概览
     */
    @RequiresPermissions("pims:overview:edit")
    @GetMapping("/edit/{overviewId}")
    public String edit(@PathVariable("overviewId") Long overviewId, ModelMap mmap)
    {
        RyStockOverview ryStockOverview = ryStockOverviewService.selectRyStockOverviewByOverviewId(overviewId);
        mmap.put("ryStockOverview", ryStockOverview);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存概览
     */
    @RequiresPermissions("pims:overview:edit")
    @Log(title = "库存概览", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RyStockOverview ryStockOverview)
    {
        return toAjax(ryStockOverviewService.updateRyStockOverview(ryStockOverview));
    }

    /**
     * 删除库存概览
     */
    @RequiresPermissions("pims:overview:remove")
    @Log(title = "库存概览", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ryStockOverviewService.deleteRyStockOverviewByOverviewIds(ids));
    }
}
